Imports System.Xml
Namespace Common.Rss.Version20
    Public Class Image
        Dim _Source As Uri
        Dim _Description As String
        Dim _Width As Integer = 88
        Dim _Height As Integer = 31
        Public Property Source() As Uri
            Get
                Return _Source
            End Get
            Set(ByVal value As Uri)
                _Source = value
            End Set
        End Property
        Public Property Description() As String
            Get
                Return _Description
            End Get
            Set(ByVal value As String)
                _Description = value
            End Set
        End Property
        Public Property Width() As Integer
            Get
                Return _Width
            End Get
            Set(ByVal value As Integer)
                _Width = value
                If value > 144 Then _Width = 144
                If value <= 0 Then _Width = 88
            End Set
        End Property
        Public Property Height() As Integer
            Get
                Return _Height
            End Get
            Set(ByVal value As Integer)
                _Height = value
                If value > 400 Then _Height = 400
                If value <= 0 Then _Height = 31
            End Set
        End Property

        Public Function ToXMLElement(ByVal document As XmlDocument, ByVal channel As Channel)
            Dim xElement As XmlElement = document.CreateElement("item")
            xElement.AppendChild(CreateXMLElement(document, "url", _Source.ToString))
            xElement.AppendChild(CreateXMLElement(document, "title", channel.Title))
            xElement.AppendChild(CreateXMLElement(document, "link", channel.Link.ToString))
            If _Width <> 88 Then
                xElement.AppendChild(CreateXMLElement(document, "width", _Width))
            End If
            If _Height <> 31 Then
                xElement.AppendChild(CreateXMLElement(document, "height", _Width))
            End If
            If _Description <> "" Then
                xElement.AppendChild(CreateXMLElement(document, "description", _Description))
            End If
            Return xElement
        End Function
        Private Function CreateXMLElement(ByVal document As XmlDocument, ByVal name As String, ByVal value As String) As XmlElement
            Dim m_Buffer As XmlElement = document.CreateElement(name)
            m_Buffer.InnerText = value
            Return m_Buffer
        End Function
    End Class
End Namespace